﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.ObjectModel;
namespace BallData
{
    public class FilterLeagueData : IListenFilter
    {
        private MainUIControl uicontrol;

        public MainUIControl Uicontrol
        {
            get { return uicontrol; }
            set { uicontrol = value; }
        }
        public void OnListenFilter(Bet007_Match bi, Match_FilterItemBind fi, Bet007_AnalysisData ba)
        {
            if (fi.bFilter)
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;

                if (ba.hostlist.Count == 0)
                    return;
                if (ba.vistlist.Count == 0)
                    return;
                //{ "得分","排名","胜率"};

                Bet007_TeamSum bt = ba.hostlist[0];

                Bet007_TeamSum vt = ba.vistlist[0];

                if (fi.szSelectFilterType == "得分" && Regex.IsMatch(fi.szFilter, "^[\\d\\.]+$") && Regex.IsMatch(bt.defen, "^[\\d\\.]+$") && Regex.IsMatch(vt.defen, "^[\\d\\.]+$") )//判断是否数字
                {
                    if (Math.Abs(Convert.ToInt32(bt.defen) - Convert.ToInt32(vt.defen)) >= Convert.ToInt32(fi.szFilter))
                    {
                        MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                        if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                        {

                            Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                            {
                                matchlist.Add(matchlistdatatemple);
                                Uicontrol.NotifyFilterMatchOk();
                            }));
                        }
                        else
                        {
                            Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                        }
                    
                    }
                    
                }
                if (fi.szSelectFilterType == "排名" && Regex.IsMatch(fi.szFilter, "^[\\d\\.]+$") && Regex.IsMatch(bt.paiming, "^[\\d\\.]+$") && Regex.IsMatch(vt.paiming, "^[\\d\\.]+$"))//判断是否数字
                {
                    if (Math.Abs(Convert.ToInt32(bt.paiming) - Convert.ToInt32(vt.paiming)) >= Convert.ToInt32(fi.szFilter))
                    {
                        MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                        if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                        {

                            Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                            {
                                matchlist.Add(matchlistdatatemple);
                                Uicontrol.NotifyFilterMatchOk();
                            }));
                        }
                        else
                        {
                            Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                        }

                    }

                }
                if (fi.szSelectFilterType == "胜率" && Regex.IsMatch(fi.szFilter, "^[\\d\\.%]+$") && Regex.IsMatch(bt.paiming, "^[\\d\\.%]+$") && Regex.IsMatch(vt.paiming, "^[\\d\\.%]+$"))//判断是否数字
                {
                    bt.shenglv = bt.shenglv.Replace('%', '0');
                    vt.shenglv = vt.shenglv.Replace('%', '0');
                    if (Math.Abs(Convert.ToInt32(bt.shenglv) - Convert.ToInt32(vt.shenglv)) >= Convert.ToInt32(fi.szFilter))
                    {
                        MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                        if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                        {

                            Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                            {
                                matchlist.Add(matchlistdatatemple);
                                Uicontrol.NotifyFilterMatchOk();
                            }));
                        }
                        else
                        {
                            Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                        }

                    }

                }   
            
            }
        
        }
    }
}
